package com.platform.coreentity.base;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

/**
 * describe:
 *
 * @author rainly
 * @date 2019/07/24
 * @time 09:52
 */
@Data
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {

    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date cteateTime;

    @LastModifiedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    private Date editTime;

    @CreatedBy
    @Column(length = 50)
    private String createBy;

    @LastModifiedBy
    @Column(length = 50)
    private String editor;

    private int isDelete;

    @PrePersist
    protected void onCreate(){
        isDelete = 0;
        cteateTime = new Date();
        editTime = new Date();
    }

}
